/*
 * 项 目 名  :   chopsticksdoctor
 * 作      者  :  Li Jun
 * 类      名  :  HSelector.java
 * 包      名  :  com.dw.chopsticksdoctor.widget.HSelector
 * 当前修改时间 :  2019年04月19日 11:58:06
 * 上次修改时间 :  2019年03月30日 19:51:16
 * Copyright (c) 2019  重庆中联信息产业有限责任公司 http://www.zlsoft.com
 *
 */

package com.zlsoft.web.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.zlsoft.mobilenurse.R;
import com.xw.repo.XEditText;

import androidx.appcompat.app.AlertDialog;

/**
 * @author loper7
 * @date 2017-04-24 pic16:pic16
 * @Description: ${todo} 背景透明dialog
 */
public class HSelector {



  /**
   * 输入dialog
   *
   * @param context
   */
  public static void edit(Context context, final TransparentDialogListener.OnEdit onEdit) {
    View view = LayoutInflater.from(context).inflate(R.layout.dialog_alert_edit, null);
    int width = (int) (DisplayUtil.getMobileWidth(context) * 0.8);
    view.setLayoutParams(new ViewGroup.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT));

    final AlertDialog dialog = new AlertDialog.Builder(context,R.style.alertDialogTheme).
        setView(view)
        .setCancelable(true)
        .create();
    dialog.setCanceledOnTouchOutside(true);

    TextView tv_cancel, tv_submit, tv_title;
    final XEditText editText;
    editText = (XEditText) view.findViewById(R.id.dialog_select_content);
    tv_cancel = (TextView) view.findViewById(R.id.dialog_select_cancel);
    tv_submit = (TextView) view.findViewById(R.id.dialog_select_submit);


    tv_cancel.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        dialog.dismiss();
        if (onEdit != null) { onEdit.onCancel(); }
      }
    });

    tv_submit.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        dialog.dismiss();
        if (onEdit != null) { onEdit.onEdit(dialog, editText.getText().toString()); }
      }
    });

    dialog.show();
  }




  public interface TransparentDialogListener {

    interface OnEdit {
      void onEdit(AlertDialog dialog, String value);
      void onCancel();
    }


  }


}


